﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HB.Base;
using HB.Expand;
namespace Test
{
    class checkerTest
    {
        public checkerTest()
        {

        }
        Dictionary<string, string> DB = new Dictionary<string, string>();
        /// <summary>
        /// 保存个人信息，每项条件限定如下，要求错误时指明具体不符合项
        /// </summary>
        /// <param name="id">个人ID</param>
        /// <param name="name">名称长度为1,12</param>
        /// <param name="age">年龄0-200</param>
        /// <param name="heightcm">身高1,300cm</param>
        /// <param name="weightkg">体重1,200kg</param>
        /// <param name="sex">男，女，其他</param>
        /// <returns></returns>
        public string CheckInfo(string id, string name, int age, int heightcm, double weightkg, string sex)
        {
            if (!DB.ContainsKey(id))
            {
                return "无法找到指定的ID";
            }
            if (string.IsNullOrEmpty(name))
            {
                if (name.Length < 1 || name.Length > 12)
                {
                    return "名称长度为1,12";
                }
            }
            if (age < 0 || age > 200)
            {
                return "年龄为0-200";
            }
            if (heightcm < 1 || heightcm > 300)
            {
                return "身高为1,300cm";
            }
            if (weightkg < 1 || weightkg > 200)
            {
                return "体重1,200kg";
            }
            if (string.IsNullOrEmpty(sex))
            {
                string[] sexs = new string[] { "男", "女", "其他" };
                if (!sex.Contains(sex))
                {
                    return "性别错误";
                }
            }
            return null;
        }

        public string CheckInfo_Use_HB_Expand(string id, string name, int age, int heightcm, double weightkg, string sex)
        {
            if (!DB.ContainsKey(id))
            {
                return "无法找到指定的ID";
            }
            if (!name.BetweenIn(1, 12))
            {
                return "名称长度为1,12";
            }
            if (!age.BetweenIn(0, 200))
            {
                return "年龄为0-200";
            }
            if (heightcm.BetweenIn(1, 300))
            {
                return "身高为1,300cm";
            }
            if (weightkg.BetweenIn(1, 200))
            {
                return "体重1,200kg";
            }
            if (sex.IsContainBy("男", "女", "其他"))
            {
                return "性别错误";
            }
            return null;
        }
        public string CheckInfo_Use_HB_Expand_Checker(string id, string name, int age, int heightcm, double weightkg, string sex)
        {
            Checker C = new Checker();
            C.Check("无法找到指定的ID", () => DB.ContainsKey(id));
            C.Check("名称长度为1,12", () => name.BetweenIn(1, 12));
            C.Check("年龄为0-200", () => heightcm.BetweenIn(1, 300));
            C.Check("体重1,200kg", () => weightkg.BetweenIn(1, 200));
            C.Check("性别错误", () => sex.IsContainBy("男", "女", "其他"));
            return C.Msg;


        }
        public class Student
        {
            public string id { get; set; }
            public string name { get; set; }
        }
        //确认name的长度是否为1,12
        public bool cc1(Student s)
        {
            Checker C = new Checker();
            C.Check("对象不能为null", () => s != null);
            C.Check("姓名长度为1,12", () => s.name.BetweenIn(1, 12));
            return C.CanContinue;
        }
        public void cc2(Student s)
        {
            Checker C = new Checker();
           // C.Check("对象不能为null", s != null);
          //  C.Check("姓名长度为1,12", s.name.BetweenIn(1, 12));//此时s如果是null，将报错
           // return C.CanContinue;
        }
    }
}
